<template>
  <div>
    <Head/>
    <left/>
    <div style="position: absolute;top: 60px;left: 200px">
      <h1>申请进来了</h1>
      {{ params }}
      <div v-for="i in params['params']" :key="i.name">
        <p v-if="i.type=='select'">{{ i.w }}
          <select name="" id="" v-model="form[i.name]">
            <option :value="j.name" v-for="j in i['value']" :key="j.id">{{ j.name }}</option>
          </select>
        </p>
        <p v-else-if="i.type=='text'">
          {{ i.name }}<input type="text" v-model="form[i.name]">
        </p>
        <p v-else-if="i.type=='date'">{{ i.name }}<input type="datetime-local" v-model="form[i.name]"></p>
        <p v-else-if="i.type=='radio'">{{ i.name }}<input type="radio" v-model="form[i.name]"></p>
        <p v-else-if="i.type=='checkbox'">{{ i.name }}<input type="checkbox" v-model="form[i.name]"></p>

      </div>
      审批人
      <van-checkbox-group v-model="result" direction="horizontal">
        <van-checkbox :name="i.level" v-for="i in zhiwu" :key="i.id">{{ i.name }}</van-checkbox>
      </van-checkbox-group>
      <van-button @click="add">提交</van-button>
    </div>

  </div>

</template>

<script>
import head from "@/components/head";
import left from "@/components/left";
import maxios from "@/http/axios";
import axios from 'axios'

export default {
  components: {
    "Head": head,
    "left": left
  },
  name: "show_shenq",
  data() {
    return {
      id: this.$route.query.id,
      holiday: {},
      params: [],
      form: {},
      zhiwu: [],
      result: [],

    }
  },
  methods: {
    getholiday() {
      maxios('/work/holiday?id=' + this.id, 'get').then(res => {
        // this.holiday = res.list
        console.log(res.list)
        this.params = res.list
        this.form.title = res.list['name']
        console.log(this.holiday)
      })
    },
    add() {
      let data = new FormData()
      data.append('title', this.form.title)
      data.append('params', JSON.stringify(this.form))
      data.append('userid', localStorage.getItem('userid'))
      data.append('zhiwu', JSON.stringify(this.result))
      axios({'url': '/work/holiday', 'method': 'post', data: data}).then(res => {
        if (res.code == 200) {
          alert('ok，等待审核')
        }
      })

    },
    get_zhiwu() {
      maxios('/compan/zhiwu', 'get')
          .then(res => {
            if (res.code == 200) {
              this.zhiwu = res.list
            }
          })
    },


  },
  mounted() {
    this.getholiday()
    this.get_zhiwu()
  }
}
</script>

<style scoped>

</style>